//
//  HLGroupRequest.m
//  YueYue
//
//  Created by hulu001 on 2023/5/20.
//

#import "HLGroupRequest.h"

@implementation HLGroupRequest
{
    HLGroupRequestType _type;
    NSDictionary *_params;
}
- (instancetype)initWithType:(HLGroupRequestType)type params:(NSDictionary *)params
{
    self = [super init];
    if (self) {
        _type = type;
        _params = params;
    }
    return self;
}

- (NSString *)requestUrl
{
    switch (_type) {
        case HLGroupRequestTypeGetGroupList: // 查询分组列表
            {
                return @"/get/customer/group";
            }
            break;
        case HLGroupRequestTypeGetUserListOfGroup: // 查询分组内的用户
            {
                return @"/get/customer/group/user";
            }
            break;
        case HLGroupRequestTypeAddUser: // 添加用户到组
            {
                return @"/add/customer/group/user";
            }
            break;
        case HLGroupRequestTypeDeleteUser: // 从组删除用户
            {
                return @"/delete/customer/group/user";
            }
            break;
        case HLGroupRequestTypeAddGroup: // 添加编辑组
            {
                return @"/modify/customer/group";
            }
            break;
            
        default:
            break;
    }
    return @"";
}

- (YTKRequestMethod)requestMethod
{
    switch (_type) {
        case HLGroupRequestTypeGetGroupList: // 查询分组列表
            {
                return YTKRequestMethodGET;
            }
            break;
        case HLGroupRequestTypeGetUserListOfGroup: // 查询分组内的用户
            {
                return YTKRequestMethodGET;
            }
            break;
        case HLGroupRequestTypeAddUser: // 添加用户到组
            {
                return YTKRequestMethodPOST;
            }
            break;
        case HLGroupRequestTypeDeleteUser: // 从组删除用户
            {
                return YTKRequestMethodGET;
            }
            break;
        case HLGroupRequestTypeAddGroup: // 添加编辑组
            {
                return YTKRequestMethodPOST;
            }
            break;
            
        default:
            break;
    }
    return YTKRequestMethodGET;
}

- (id)requestArgument
{
    return _params;
}

- (NSArray<HLGroupModel *> *)groupList
{
    NSArray *lists = @[];
    NSArray *data = [self.result valueForKey:@"data"];
    if (![data isKindOfClass:[NSArray class]]  || ![self isSuccess]){
        return lists;
    }
    
    if (data.count > 0) {
       lists = [HLGroupModel mj_objectArrayWithKeyValuesArray:data];
    }
    return lists;
}

- (NSArray<HLGroupUserModel *> *)groupUserList
{
    NSArray *lists = @[];
    NSArray *data = [self.result valueForKey:@"data"];
    if (![data isKindOfClass:[NSArray class]]  || ![self isSuccess]){
        return lists;
    }
    
    if (data.count > 0) {
       lists = [HLGroupUserModel mj_objectArrayWithKeyValuesArray:data];
    } else {
        // test
        HLGroupUserModel *model1 = [HLGroupUserModel.alloc init];
        model1.avatar = @"";
        model1.nickName = @"Test1";
        
        HLGroupUserModel *model2 = [HLGroupUserModel.alloc init];
        model2.avatar = @"";
        model2.nickName = @"Test2";
        
        lists = @[model1, model2];
    }
    
    return lists;
}
@end
